import Vue from "vue";

import App from "./App.vue";
import router from "./router/index.js";

import Vuex from "vuex";

Vue.use(Vuex);

const SET_COUNT = "SET_COUNT";
const SET_GENDER = "SET_GENDER";
const store = new Vuex.Store({
  state: {
    count: 5,
    gender: 1,
  },
  getters: {
    g1: () => 100,
    g2: () => 200,
    g3: (state, getters) => getters.g1 + getters.g2 + state.count,
    cnGender(state) {
      return { 1: "男", 2: "女" }[state.gender];
    },
  },
  mutations: {
    [SET_COUNT]: (state, value) => (state.count += value),
    [SET_GENDER]: (state, value) => (state.gender = value),
  },
  actions: {
    // methods
    add() {
      console.log("add", 100);
    },
  },
});

new Vue({
  render: (h) => h(App),
  router, //路由注入
  store, //状态注入 Vue.protype.store = new Vue();
}).$mount("#app");
